package com.smartmedical.patient.userInquiry.controller;

import com.smartmedical.common.core.domain.HealthR;
import com.smartmedical.patient.userInquiry.domain.dto.param.EvaluateParam;
import com.smartmedical.patient.userInquiry.domain.vo.*;
import com.smartmedical.patient.userInquiry.service.InquiryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.github.pagehelper.page.PageMethod.startPage;

@RestController
@RequestMapping("/user/inquiry")
public class InquiryController {
    @Autowired
    private InquiryService inquiryService;

    /**
     * 根据科室查询医生列表数据，支持分页
     * @RequestParam入参 deptId 科室id
     * condition 1=综合，2=好评 ，3=咨询数 ，4= 价格
     * sortBy 排序字段(当条件为4时，1=按高价格排序，不传为默认排序)
     * page 页码
     * count 每页条数
     */
    @GetMapping("v1/findDoctorList")
    public HealthR<List<DoctorVo>> findDoctorList(@RequestParam(value = "deptId") Integer deptId,
                                                  @RequestParam(value = "condition") Integer condition,
                                                  @RequestParam(value = "sortBy") Integer sortBy,
                                                  @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value = "count", defaultValue = "5") Integer count) {
        startPage(page, count);
        return HealthR.ok(inquiryService.findDoctorList(deptId, condition, sortBy));
    }

    /**
     * 查询医生明细信息
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证
     * @RequestParam入参 doctorId 医生id
     */
    @GetMapping("v1/findDoctorInfo")
    public HealthR<DoctorVo> findDoctorInfo(@RequestParam("doctorId") Integer doctorId) {
        return HealthR.ok(inquiryService.findDoctorInfo(doctorId));
    }

    /**
     * 咨询医生
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     * @RequestParam入参 doctorId 医生id
     */
    @GetMapping("verify/v1/consultDoctor")
    public HealthR<String> consultDoctor(@RequestParam(value = "doctorId") int doctorId ,@RequestParam(value = "sessionId") String sessionId ,@RequestParam(value = "userId") int userId) {
        return HealthR.ok(inquiryService.consultDoctor(doctorId));
    }

    /**
     * 用户关注医生操作
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     * @RequestParam入参 doctorId 医生id
     */
    @GetMapping("/verify/v1/followDoctor")
    public HealthR<String> followDoctor(@RequestParam(value = "doctorId") int doctorId ,@RequestParam(value = "sessionId") String sessionId ,@RequestParam(value = "userId") int userId) {
        return HealthR.ok(inquiryService.followDoctor(doctorId));
    }

    /**
     * 用户取消关注医生操作
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     * @RequestParam入 doctorId 医生id
     */
    @DeleteMapping("verify/v1/cancelFollow")
    public HealthR<String> cancelFollow(@RequestParam(value = "doctorId") int doctorId,@RequestParam(value = "sessionId") String sessionId,@RequestParam(value = "userId") int userId) {
        return HealthR.ok(inquiryService.cancelFollow(doctorId));
    }

    /**
     * 结束问诊
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     * @RequestParam入参 recordId 问诊记录id
     */
    @PutMapping("verify/v1/endInquiry")
    public HealthR endInquiry(@RequestParam(value = "recordId") int recordId) {
        inquiryService.endInquiry(recordId);
        return HealthR.ok();
    }

    /**
     * 用户评论问诊服务
     *
     * @RequestHeader入参 userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     */
    @GetMapping("verify/v1/evaluationInquiry")
    public HealthR evaluationInquiry(@RequestBody EvaluateParam evaluateParam) {
        inquiryService.evaluateInquiry(evaluateParam);
        return HealthR.ok();
    }

    /**
     * 送礼物
     * @RequestHeader入参
     * userId 用户id
     * sessionId 用户登陆凭证（非必须参数）
     * @RequestParam入参 inquiryRecordId 问诊记录id
     * giftId
     */
    @PutMapping("verify/v1/handselGift")
    public HealthR handselGift(@RequestParam(value = "inquiryRecordId") int inquiryRecordId,
                               @RequestParam(value = "giftId") int giftId) {
        inquiryService.updEvaluateInquiry(inquiryRecordId, giftId);
        return HealthR.ok();
    }
    /**
     * 查看当前问诊
     * @RequestHeader入参
     * 用户id userId
     * 用户登陆凭证 sessionId
     */
    @GetMapping("verify/v1/findCurrentInquiryRecord")
    public HealthR<InquiryRecordVo> findCurrentInquiryRecord() {
        return HealthR.ok(inquiryService.findCurrentInquiryRecord());
    }

    /**
     * 用户查看历史问诊
     * @RequestHeader入参
     * 用户id userId
     * 用户登陆凭证 sessionId
     * @RequestParam入参
     * 当前页 page
     * 当前页条数 count
     */
    @GetMapping("verify/v1/findHistoryInquiryRecord")
    public HealthR<List<InquiryRecordVo>> findHistoryInquiryRecord(@RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "count", defaultValue = "5") int count) {
        startPage(page, count);
        return HealthR.ok(inquiryService.findHistoryInquiryRecord());
    }


    /**
     * 查询历史问诊聊天记录
     * @RequestHeader入参
     * 用户id userId
     * 用户登陆凭证 sessionId
     * @RequestParam入参
     * inquiryId 问诊id
     * 当前页 page
     * 当前页条数 count
     */
    @GetMapping("verify/v1/findInquiryRecordList")
    public HealthR<List<InquiryDetailsRecordVo>> findInquiryRecordList(@RequestParam(value = "inquiryId") int inquiryId , @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "count", defaultValue = "5") int count) {
        startPage(page, count);
        return HealthR.ok(inquiryService.findInquiryRecordList(inquiryId));
    }

    /**
     * 查询问诊评价详情
     * @RequestHeader入参
     * 用户id userId
     * 用户登陆凭证 sessionId
     * @RequestParam入参
     * recordId 问诊记录id
     */
    @GetMapping("verify/v1/findDoctorEvaluate")
    public HealthR<DoctorEvaluateVo> findDoctorEvaluate(@RequestParam(value = "recordId") int recordId) {
        return HealthR.ok(inquiryService.findDoctorEvaluate(recordId));
    }

    /**
     * 查询礼物列表
     */
    @GetMapping("v1/findGiftList")
    public HealthR<List<GiftVo>> findGiftList() {
        return HealthR.ok(inquiryService.findGiftList());
    }
    /**
     * 查询医生评价列表
     * @RequestParam入参
     * doctorId 医生id
     * 当前页 page
     * 当前页
     */
    @GetMapping("v1/findDoctorEvaluateList")
    public HealthR<List<CommentVo>> findDoctorEvaluateList(@RequestParam(value = "doctorId") int doctorId, @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "count", defaultValue = "5") int count) {
        startPage(page, count);
        return HealthR.ok(inquiryService.findDoctorEvaluateList(doctorId));
    }




}
